package com.cskaoyan.shopping.api;

import com.cskaoyan.mall.commons.api.CartsForOrder;
import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.mall.dto.ProductDetailServiceResponse;
import com.cskaoyan.shopping.service.IProductService;
import com.cskaoyan.shopping.service.IShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther cskaoyan  处理服务调用请求
 */
@RestController
public class OrderApiImpl {

    @Autowired
    IProductService productService;

    @Autowired
    IShoppingCartService iShoppingCartService;

    @GetMapping(value = "/rpc/product/detail")
    ServiceCallResponse<ProductDetailDto> getProductDetail(@RequestParam("id") Long id) {
        ProductDetailDto productDetail = productService.getProductDetail(id);
        ServiceCallResponseUtil<ProductDetailDto> responseUtil = new ServiceCallResponseUtil<>();
        return responseUtil.ok(productDetail);
    }


    @PostMapping("/delete/carts")
    Integer deleteCarts(@RequestBody CartsForOrder cartsForOrder){
        try {
            iShoppingCartService.cartsForOrder(cartsForOrder);
        }catch (Exception e){
            return 0;
        }
        return 1;
    }
}
